//首次加载服务类，用于队列
function loadService(app) {
  return async function (ctx, next) {
    if (app.service === {}) {
      const fileBase = __dirname + "/../../../";
      require("young-require-all")({
        dirname: fileBase + "module",
        filter: /(.+)\.ts$/,
        resolve: function (Service) {
          for (let ServiceName in Service) {
            let name = Service[ServiceName].name;
            app.service[name] = new Service[ServiceName](ctx);
          }
        },
      });
    }
    await next();
  };
}
module.exports = { loadService };
